using System.Collections.Generic;
using CoreGraphics;
using Foundation;
using mb;
using mb.iOS;
using Masonry;
using MyExtensions;
using UIKit;

namespace libmp
{
    using InsertInfoList = List < (UIView view, int index, int height, int stickyHeight) >;
    class VCHistoryRecordController : VCExMovieList
    {
        UIView titleBar;
        int HeaderHeight = 48;
        string userId;
        public VCHistoryRecordController()
        {
            userId = User.me.id;
        }
        public override void ViewDidLoad()
        {
            var bkView = new UIView() { BackgroundColor = Util.MainBKColor };
            bkView.SetParent(View).MakeConstraints(m =>
            {
                m.Top.EqualTo(this.TopLayoutGuideBottom());
                m.Left.Right.Bottom.EqualTo(View);
            });
            base.ViewDidLoad();
            SetTitleBar("历史记录1");

            listView.RemakeConstraints(m =>
            {
                m.Left.Right.EqualTo(View);
                m.Top.EqualTo(this.TopLayoutGuideBottom()).Offset(HeaderHeight);
                m.Bottom.EqualTo(this.BottomLayoutGuideTop());
            });

            this.dataSource = DataStore.store.GetHistoryVideos(1); //临时取1号分类ID的视频
            this.Reload();
        }

        void SetTitleBar(string titleName)
        {
            titleBar = new UIView()
            {
                BackgroundColor = Util.MainColor,
            };
            titleBar.SetParent(View);
            titleBar.Frame = new CGRect(0, 0, View.Frame.Size.Width, 48);
            titleBar.MakeConstraints(m =>
            {
                m.Top.EqualTo(this.TopLayoutGuideBottom());
                m.Width.Left.EqualTo(View);
                m.Height.EqualTo(NSObject.FromObject(HeaderHeight));
            });
            var btnPicWidth = 15;
            var btnPicHeight = 15;

            var topBarLeftView = new UIView();
            topBarLeftView.SetParent(titleBar);
            topBarLeftView.MakeConstraints(m =>
            {
                m.Left.EqualTo(NSObject.FromObject(10));
                m.Top.EqualTo(titleBar);
                m.Bottom.EqualTo(titleBar);
                m.Width.EqualTo(NSObject.FromObject((View.Bounds.Width - 20) / 3));
            });

            var leftButton1 = new UIButton();
            leftButton1.Frame = new CGRect(0, 14, btnPicWidth + 30, btnPicHeight + 5);
            leftButton1.SetParent(topBarLeftView);
            var leftButton1ImageView = new UIImageView();
            var imgoperationArrow1 = UIImage.FromFile($"{App.HotStorageRoot}/res/user/Fanhui.png");
            leftButton1ImageView.Image = new UIImage(imgoperationArrow1.CGImage, 2, UIImageOrientation.Up);
            leftButton1ImageView.SetParent(leftButton1);
            leftButton1ImageView.MakeConstraints(m =>
            {
                m.CenterY.EqualTo(leftButton1.CenterY());
                m.Left.EqualTo(NSObject.FromObject(5));
                m.Height.EqualTo(NSObject.FromObject(btnPicHeight));
                m.Width.EqualTo(NSObject.FromObject(btnPicWidth / 2));
            });
            var leftButton2Label = new UILabel();
            leftButton2Label.Text = "返回";
            leftButton2Label.Font = UIFont.SystemFontOfSize(12);
            leftButton2Label.SetParent(leftButton1);
            leftButton2Label.TextColor = UIColor.White;
            leftButton2Label.MakeConstraints(m =>
            {
                m.CenterY.EqualTo(leftButton1.CenterY());
                m.Left.EqualTo(NSObject.FromObject(20));
                m.Height.EqualTo(NSObject.FromObject(btnPicHeight));
                m.Width.EqualTo(NSObject.FromObject(btnPicWidth + 20));
            });
            leftButton1.TouchUpInside += (s, e) =>
            {
                logger.Log("返回====>");
                AppDelegate.Instance.NavController.PopViewController(false);
            };

            var topBarMiddleView = new UIView();
            topBarMiddleView.SetParent(titleBar);
            topBarMiddleView.MakeConstraints(m =>
            {
                m.Left.EqualTo(topBarLeftView.Right());
                m.Top.EqualTo(titleBar);
                m.Bottom.EqualTo(titleBar);
                m.Width.EqualTo(NSObject.FromObject((View.Bounds.Width - 20) / 3));
            });

            var middleLabel = new UILabel();
            middleLabel.Text = titleName;
            middleLabel.Font = UIFont.BoldSystemFontOfSize(18);
            middleLabel.SetParent(topBarMiddleView);
            middleLabel.TextColor = UIColor.White;
            middleLabel.MakeConstraints(m =>
            {
                m.CenterY.EqualTo(topBarMiddleView.CenterY());
                m.CenterX.EqualTo(topBarMiddleView.CenterX());
            });

            var topBarRightView = new UIView();
            topBarRightView.SetParent(titleBar);
            topBarRightView.MakeConstraints(m =>
            {
                m.Left.EqualTo(topBarMiddleView.Right());
                m.Top.EqualTo(titleBar);
                m.Bottom.EqualTo(titleBar);
                m.Width.EqualTo(NSObject.FromObject((View.Bounds.Width - 20) / 3));
            });
        }
    }
}